package lei.h_java8特性.方法引用;

/**
 * @className: MethodReferenceExample02
 * @author: xl
 * @date: 2025/3/1 16:08
 * @Version: 1.0
 * @description:
 */

import java.util.function.Function;

public class MethodReferenceExample02 {
    public static void main(String[] args) {
        // 使用 Lambda 表达式
        Function<String, Person> lambda = name -> new Person(name);

        // 使用构造方法引用
        Function<String, Person> methodRef = Person::new;

        Person person1 = lambda.apply("Alice");
        Person person2 = methodRef.apply("Bob");

        System.out.println(person1.getName()); // 输出: Alice
        System.out.println(person2.getName()); // 输出: Bob
    }
}

class Person {
    private String name;

    public Person(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
}

